package com.ruoyi.wecom.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.business.domain.dto.admin.wecom.WecomChatGroupWelAddDTO;
import com.ruoyi.business.domain.fission.TbWecomChatGroupWel;
import com.ruoyi.business.service.wecom.ITbWecomChatGroupWelService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.util.Arrays;

@Validated
@Api(value = "企微入群欢迎语管理", tags = {"企微入群欢迎语管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/wecom/group/wel")
public class WecomInGroupWelController extends BaseController {

    @Resource
    private ITbWecomChatGroupWelService tbWecomChatGroupWelService;

    /**
     * 新增企微入群欢迎语
     */
    @ApiOperation("新增企微入群欢迎语")
    @SaCheckPermission("wecom:group:wel:add")
    @PostMapping("/sys-add")
    public R<Boolean> sysAdd(@Validated @RequestBody WecomChatGroupWelAddDTO addWecomChatGroupWelDTO) {
        return R.ok(tbWecomChatGroupWelService.addWecomWel(addWecomChatGroupWelDTO));
    }

    /**
     * 分页查询入群欢迎语
     */
    @ApiOperation("管理台分页查询入群欢迎语")
    @SaCheckPermission("wecom:group:wel:page")
    @GetMapping("/sys-page")
    public TableDataInfo<TbWecomChatGroupWel> sysPage(PageQuery pageQuery) {
        return tbWecomChatGroupWelService.sysPageQuery(pageQuery);
    }

    /**
     * 删除入群欢迎语
     */
    @ApiOperation("删除入群欢迎语")
    @SaCheckPermission("wecom:group:wel:del")
    @DeleteMapping("/sys-del/{ids}")
    public R<Boolean> sysDel(@ApiParam("主键串") @NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return R.ok(tbWecomChatGroupWelService.deleteByIds(Arrays.asList(ids)));
    }

}
